import { createBrowserRouter, redirect, useRoutes } from 'react-router-dom'
import NotFound from '../views/NotFond'
import Login from '../views/Login/login'
import { Navigate } from 'react-router-dom'
import Layout from '../layout/layout'
import UserList from '../views/UserList/userList'
import Dashboard from '../views/Dashboard/dashboard'
import MenuList from '../views/MenuList/menu'
import RoleList from '../views/RoleList/roleList'
import DeptList from '../views/DeptList/deptList'
import { Loader } from './loader'
import Welcome from '../views/welcome/welcome'
//引入lazy方法组件懒加载
import { Lazy } from './lazy'
const router = createBrowserRouter([
  {
    id: 'layout',
    loader: Loader,
    element: <Layout />,
    children: [
      {
        path: 'welcome',
        //使用lazy方法组件懒加载
        //首个页面尽量不用懒加载=，报错了
        element: <Welcome></Welcome>
      },
      {
        path: 'dashboard',
        // element: <Dashboard></Dashboard>
        element: Lazy(() => import('../views/Dashboard/dashboard'))
      },
      {
        path: 'userList',
        // element: <UserList />
        element: Lazy(() => import('../views/UserList/userList'))
      },
      {
        path: 'menuList',
        element: <MenuList />
      },
      {
        path: 'roleList',
        element: <RoleList />
      },
      {
        path: 'deptList',
        element: <DeptList />
      }
    ]
  },
  {
    path: '/',

    element: <Navigate to={'/welcome'} />
  },

  {
    path: '/login',
    element: <Login />
  },

  {
    path: '*',
    element: <NotFound />
  }
])

export default router
